package xyz.zdsoft.ask_for_leave_manage_module.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import xyz.zdsoft.ask_for_leave_manage_module.vo.*;
import xyz.zdsoft.ask_for_leave_manage_module.service.StudentLeaveService;
import xyz.zdsoft.ask_for_leave_manage_module.bo.LeaveBo;
import xyz.zdsoft.common.utils.Result;
import xyz.zdsoft.common.utils.ResultBody;


/**
 * @author 夏兵
 */
@RestController
@Api(tags = "学生请假功能模块")
@RequestMapping("/api/student")
@Validated
public class StudentLeavesController {

    @Autowired
    private StudentLeaveService studentLeaveService;

    @GetMapping("/queryStudentLeave")
    @ApiOperation("查询当前学生的请假记录(分页和模糊)")
    @ApiOperationSupport(ignoreParameters = {"reason","id"})
    public Result<LeaveVo> queryStudentLeave(LeaveBo leaveBo) {
        return studentLeaveService.queryCurStuLeaves(leaveBo);
    }

    @ApiOperation("查询学生请假的基本信息")
    @GetMapping("/queryCurStuBaseInfo")
    public Result<CurStuLeaveBaseInfoVo> queryCurStuBaseInfo() {
        return studentLeaveService.queryCurStuBaseInfo();
    }

    @ApiOperation("查询学生请假失败的原因")
    @GetMapping("/queryFailReasonByLeaId")
    @ApiImplicitParam(name = "leaveId", value = "请假id", required = true)
    public Result<String> queryFailReasonByLeaId(Integer leaveId) {
        return studentLeaveService.queryFailReasonByLeaId(leaveId);
    }

    @GetMapping("/askForLeave")
    @ApiOperation("学生新增请假/修改编辑")
    @ApiOperationSupport(ignoreParameters = {"current","size","status"})
    public ResultBody askForLeave(LeaveBo leaveBo) {
        return studentLeaveService.askForLeave(leaveBo);
    }

    @GetMapping("/queryCurStuLeaveRecords")
    @ApiOperation("查询当前请假的操作记录")
    @ApiImplicitParam(name = "leaveId", value = "请假id", required = true)
    public Result<LeaveRecords> queryCurStuLeaveRecords(Integer leaveId) {
        return studentLeaveService.queryCurStuLeaveRecords(leaveId);
    }

    @GetMapping("/queryLeaveDetailByLeaId")
    @ApiOperation("通过id查询本条请假记录")
    @ApiImplicitParam(name = "leaveId", value = "请假id", required = true)
    public Result<StuLeaveDetailVo> queryLeaveDetailByLeaId(Integer leaveId) {
        return studentLeaveService.queryLeaveDetailByLeaId(leaveId);
    }

    @GetMapping("/queryStuLeaveAttach")
    @ApiOperation("通过id查询本条请假记录的附件")
    @ApiImplicitParam(name = "leaveId", value = "请假id", required = true)
    public Result<StuLeaveAttachVo> queryStuLeaveAttach(Integer leaveId) {
        return studentLeaveService.queryStuLeaveAttach(leaveId);
    }
}
